package com.neuedu.nep.service.impl;

import com.neuedu.nep.dao.AqiDao;
import com.neuedu.nep.model.Aqi;
import com.neuedu.nep.model.AqiExample;
import com.neuedu.nep.model.GridCityExample;
import com.neuedu.nep.service.AqiService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 黄宇佳
 * @create 2024-04-10 15:33
 * @description:
 */
@Service
public class AqiServiceImpl implements AqiService {
    @Resource
    private AqiDao aqiDao;

    @Override
    public List<Aqi> AqiAll() {
        return aqiDao.selectByExample(null);
    }

    @Override
    public Aqi testAqi(Integer type, Integer input) {
        if (type==1){
//            so2
            if (input<0){
                input=0;
            }else if(input>2620){
                input=2620-1;
            }
            AqiExample example=new AqiExample();
            AqiExample.Criteria criteria=example.createCriteria();
            criteria.andSo2MinLessThan(input).andSo2MaxGreaterThan(input);
            List<Aqi> aqis = aqiDao.selectByExample(example);
            return aqis.get(0);
        }else if(type==2){
//            co
            if (input<0){
                input=0;
            }else if(input>150){
                input=150-1;
            }
            AqiExample example=new AqiExample();
            AqiExample.Criteria criteria=example.createCriteria();
            criteria.andCoMinLessThan(input).andCoMaxGreaterThan(input);
            List<Aqi> aqis = aqiDao.selectByExample(example);
            return aqis.get(0);
        }else{
//            PM2.5
            if (input<0){
                input=0;
            }else if(input>500){
                input=500-1;
            }
            AqiExample example=new AqiExample();
            AqiExample.Criteria criteria=example.createCriteria();
            criteria.andSpmMinLessThan(input).andSpmMaxGreaterThan(input);
            List<Aqi> aqis = aqiDao.selectByExample(example);
            return aqis.get(0);
        }
    }
}
